package  
{
	import flash.display.MovieClip;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author ...
	 */
	public class Menu extends Level_Base 
	{
		const UM_QUARTO_MENU_X:Number=Main.instance.stage.stageWidth/6;
		const UM_QUARTO_MENU_Y:Number=Main.instance.stage.stageHeight/6;
		var btPlayMenu:MovieClip;
		var btRecordMenu:MovieClip;
		var fundoMenu:MovieClip;
		var chaoMenu:MovieClip;
		var porreteMenu:MovieClip;
		var taxaAchatamento:Number;
		var superficiechaoMenu:Number;
		var superfInfQuad:Number;
		const CAIR_MENU:Boolean = false;
		var acaoporreteMenu:Boolean;
		var velocidadeYMenu:Number;
		const GRAVIDADE_MENU:Number = 3;
		const POS_INICIAL_PORRETE_MENU_Y:int = 117.2;
		var  fim:Boolean;
		
		public override function start(): void 
		{			
			btPlayMenu= new BotaoPlay();
			btRecordMenu= new BtRecordMenu();
			chaoMenu= new ChaoMenu();
			porreteMenu = new PorreteMenu();
			fundoMenu = new FundoMenu();
			btPlayMenu.x=129.85+UM_QUARTO_MENU_X;
			btPlayMenu.y=283+UM_QUARTO_MENU_Y;
			btRecordMenu.x=414.85+UM_QUARTO_MENU_X;
			btRecordMenu.y=282+UM_QUARTO_MENU_Y;
			chaoMenu.x=296.45+UM_QUARTO_MENU_X;
			chaoMenu.y=361.5+UM_QUARTO_MENU_Y;
			porreteMenu.x=130.25+UM_QUARTO_MENU_X;
			porreteMenu.y = 121 + UM_QUARTO_MENU_Y;
			Main.instance.MC_tela.addChild(fundoMenu);
			Main.instance.MC_tela.addChild(btPlayMenu);
			Main.instance.MC_tela.addChild(btRecordMenu);
			Main.instance.MC_tela.addChild(chaoMenu);
			Main.instance.MC_tela.addChild(porreteMenu);
			
			btPlayMenu.addEventListener(MouseEvent.CLICK,amassa);
			btRecordMenu.addEventListener(MouseEvent.CLICK,amassa);

			taxaAchatamento=1;
			superficiechaoMenu=chaoMenu.y-chaoMenu.height/2;
			chaoMenu.visible=false;
			acaoporreteMenu=true;
			velocidadeYMenu = 8;				
		}
		
		public override function update() 	: void 
		{
			if (porreteMenu.y >= 257 + UM_QUARTO_MENU_Y)
			{
				iniciarLevel();
			}

				validarPorreteMenu();
				superfInfQuad=porreteMenu.y+porreteMenu.height/2;
				var asd:int=superficiechaoMenu-superfInfQuad;
				taxaAchatamento=asd/100;
				
				if (acaoporreteMenu)
				{
					if (mouseX >= 0 && mouseX <= 270 + UM_QUARTO_MENU_X)
					{
						porreteMenu.x=131+UM_QUARTO_MENU_X;
					}
					else
					{
						porreteMenu.x=414+UM_QUARTO_MENU_X;
					}
				}
				if (porreteMenu.hitTestObject(btPlayMenu))
				{
					btPlayMenu.scaleY=taxaAchatamento;
					btPlayMenu.y=chaoMenu.y-chaoMenu.height/2-btPlayMenu.height/2;
				}
				if (porreteMenu.hitTestObject(btRecordMenu))
				{
					btRecordMenu.scaleY=taxaAchatamento;
					btRecordMenu.y=chaoMenu.y-chaoMenu.height/2-btRecordMenu.height/2;
				}
				if (porreteMenu.hitTestObject(chaoMenu))
				{
					porreteMenu.y=chaoMenu.y-chaoMenu.height/2-porreteMenu.height/2;
				}
			
			
		}

		public override function terminate() : void
		{
			Main.instance.MC_tela.removeChild(fundoMenu);
			Main.instance.MC_tela.removeChild(btPlayMenu);
			Main.instance.MC_tela.removeChild(btRecordMenu);
			Main.instance.MC_tela.removeChild(chaoMenu);
			Main.instance.MC_tela.removeChild(porreteMenu);
			btPlayMenu.removeEventListener(MouseEvent.CLICK,amassa);
			btRecordMenu.removeEventListener(MouseEvent.CLICK,amassa);	
		}

		public function iniciarLevel():void
		{
			LevelManager.current = new Level1();
		}

		function validarPorreteMenu():void
		{
			trace("validarPorreteMenu");
			if (acaoporreteMenu==CAIR_MENU)
			{
				validarVelocidadeporreteMenu();
			}
		}
		
		function validarVelocidadeporreteMenu():void
		{
			trace("validarVelocidadeporreteMenu");
			velocidadeYMenu +=  GRAVIDADE_MENU;
			porreteMenu.y +=  velocidadeYMenu;
		}

		function amassa(e:MouseEvent):void
		{
			trace("amassa");
			acaoporreteMenu = CAIR_MENU;
		}
		
		
	}

}